import * as echarts from 'echarts';

export const base_radar=(degreeScore,experienceScore,jobDifference,jobSuitScore,salaryScore,aveScore2)=>{
    const myChart = echarts.init(document.getElementById("main_radar"));

    let option;
    option = {
        // color: ['#67F9D8', '#FFE434', '#56A3F1', '#FF917C'],
        title: {
            text: '竞争力雷达图',
            subtext: "平均得分为："+ aveScore2 +"分",
            subtextStyle: {
                fontSize: 20, // 调整subtext字体大小
                color: 'red'
            },
        },
        legend: {
            data: ['各维度得分']
        },
        radar: {
            // shape: 'circle',
            indicator: [
                { name: '学历得分', max: 100 },
                { name: '经验得分', max: 100 },
                { name: '技术多样性得分', max: 100 },
                { name: '技术岗位适配度得分', max: 100 },
                { name: '行业薪资得分', max: 100 },
            ],
            axisName: {
                formatter: '{value}',
                color: '#428BD4'
            },
        },
        series: [
            {
                name: '各维度得分',
                type: 'radar',
                data: [
                    {
                        value: [degreeScore, experienceScore, jobDifference, jobSuitScore, salaryScore],
                        name: '各维度得分',
                        areaStyle: {
                            color: 'rgba(135, 206, 250, 0.5)'
                        },
                        label: {
                            show: true,
                            formatter: function (params) {
                                return params.value;
                            }
                        }
                    },
                ]
            }
        ]
    };
    myChart.setOption(option);
    myChart.resize();
    window.addEventListener('resize', () => myChart.resize);
}
export const skill_pie= (rankSkillMap)=> {

    const myChart = echarts.init(document.getElementById("main_pie"));

    let option;
    // 初始化一个空数组用于存放格式化后的数据
    const pieData = [];
    // 遍历对象的属性
    for (const key in rankSkillMap) {
        if (Object.prototype.hasOwnProperty.call(rankSkillMap, key)) { // 确保只访问自身的属性
            // 将每项数据构造成ECharts所需格式并添加到数组中
            pieData.push({ value: rankSkillMap[key], name: key });
        }
    }
    // 根据value从大到小对pieData进行排序
    pieData.sort((a, b) => b.value - a.value);
    option = {
        title: {
            text: "该行业前十个重要的技术",
            left: 'center'
        },
        tooltip: {
            trigger: 'item'
        },
        legend: {
            orient: 'vertical',
            left: 'left'
        },
        series: [
            {
                name: '所需技能',
                type: 'pie',
                radius: '50%',
                grid: { containLabel: true },
                data: pieData.map(item => ({ ...item, value: parseFloat(item.value), })), // 确保value是数值类型，以便计算百分比
                label: { // 添加这一部分来显示百分比
                    show: true,
                    formatter: '{b}: {d}%',
                    position: 'outer'
                },
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };
    myChart.setOption(option);
    myChart.resize();
    window.addEventListener('resize', () => myChart.resize);


}
